package entity.resources;

import levels.PathGrid;
import loading.ImageLoader;
import math.Vector2D;
import entity.Entity;

public abstract class Resource extends Entity
{
	private int amount;
	
	private PathGrid pg;

	public Resource( Vector2D pos, ImageLoader img, PathGrid pg, int initialAmount )
	{
		super( pos, img );
		
		amount = initialAmount;
		
		this.pg = pg;
		
		PathGrid.fromWorldToGrid( pos );
		
		pg.getTiles().get( (int)pos.getY() ).get( (int)pos.getX() ).setOccupied( true );
	}
	
	public void resetNode()
	{
		Vector2D pos = this.getPosition();
		
		PathGrid.fromWorldToGrid( pos );
		
		pg.getTiles().get( (int)pos.getY() ).get( (int)pos.getX() ).setOccupied( true );
	}
	
	public void take( int amount )
	{
		if( !isDepleted() )
			this.amount -= amount;
	}

	public boolean isDepleted()
	{
		return amount <= 0;
	}
}
